{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data = pd.read_excel('../HealthcareData-2.xlsx', index_col='Serial No')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data = pd.read_excel('../HealthCareData-1.xlsx',index_col='S.NO')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 288 entries, 1 to 288\n",
      "Data columns (total 41 columns):\n",
      "Age                                                                        288 non-null int64\n",
      "Gender                                                                     288 non-null object\n",
      "Place(location where the patient lives)                                    288 non-null object\n",
      "Duration of alcohol consumption(years)                                     288 non-null int64\n",
      "Quantity of alcohol consumption (quarters/day)                             288 non-null int64\n",
      "Type of alcohol consumed                                                   288 non-null object\n",
      "Hepatitis B infection                                                      288 non-null object\n",
      "Hepatitis C infection                                                      288 non-null object\n",
      "Diabetes(value)                                                            288 non-null object\n",
      "Blood pressure (mmhg)                                                      288 non-null object\n",
      "Obesity                                                                    288 non-null object\n",
      "Family history of cirrhosis/ hereditary                                    288 non-null object\n",
      "TCH                                                                        287 non-null float64\n",
      "TG                                                                         287 non-null float64\n",
      "LDL                                                                        287 non-null float64\n",
      "HDL                                                                        286 non-null float64\n",
      "Hemoglobin  (g/dl)                                                         288 non-null float64\n",
      "PCV  (%)                                                                   288 non-null float64\n",
      "RBC  (million cells/microliter)                                            288 non-null float64\n",
      "MCV   (femtoliters/cell)                                                   288 non-null int64\n",
      "MCH  (picograms/cell)                                                      288 non-null int64\n",
      "MCHC  (grams/deciliter)                                                    284 non-null float64\n",
      "Total Count                                                                288 non-null int64\n",
      "Polymorphs  (%)                                                            288 non-null float64\n",
      "Lymphocytes  (%)                                                           288 non-null float64\n",
      "Monocytes   (%)                                                            287 non-null float64\n",
      "Eosinophils   (%)                                                          287 non-null float64\n",
      "Basophils  (%)                                                             288 non-null float64\n",
      "Platelet Count  (lakhs/mm)                                                 288 non-null float64\n",
      "Total Bilirubin    (mg/dl)                                                 288 non-null float64\n",
      "Direct    (mg/dl)                                                          288 non-null float64\n",
      "Indirect     (mg/dl)                                                       288 non-null float64\n",
      "Total Protein     (g/dl)                                                   288 non-null float64\n",
      "Albumin   (g/dl)                                                           288 non-null float64\n",
      "Globulin  (g/dl)                                                           288 non-null float64\n",
      "A/G Ratio                                                                  288 non-null float64\n",
      "AL.Phosphatase      (U/L)                                                  287 non-null float64\n",
      "SGOT/AST      (U/L)                                                        288 non-null int64\n",
      "SGPT/ALT (U/L)                                                             288 non-null int64\n",
      "USG Abdomen (liver diffused or not)                                        288 non-null object\n",
      "Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)    288 non-null object\n",
      "dtypes: float64(22), int64(8), object(11)\n",
      "memory usage: 94.5+ KB\n"
     ]
    }
   ],
   "source": [
    "train_data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 950 entries, 1 to 950\n",
      "Data columns (total 41 columns):\n",
      "Age                                                                        950 non-null int64\n",
      "Gender                                                                     950 non-null object\n",
      "Place(location where the patient lives)                                    816 non-null object\n",
      "Duration of alcohol consumption(years)                                     950 non-null int64\n",
      "Quantity of alcohol consumption (quarters/day)                             950 non-null int64\n",
      "Type of alcohol consumed                                                   950 non-null object\n",
      "Hepatitis B infection                                                      950 non-null object\n",
      "Hepatitis C infection                                                      950 non-null object\n",
      "Diabetes Result                                                            950 non-null object\n",
      "Blood pressure (mmhg)                                                      950 non-null object\n",
      "Obesity                                                                    950 non-null object\n",
      "Family history of cirrhosis/ hereditary                                    950 non-null object\n",
      "TCH                                                                        591 non-null float64\n",
      "TG                                                                         591 non-null object\n",
      "LDL                                                                        591 non-null object\n",
      "HDL                                                                        582 non-null float64\n",
      "Hemoglobin  (g/dl)                                                         950 non-null float64\n",
      "PCV  (%)                                                                   920 non-null float64\n",
      "RBC  (million cells/microliter)                                            398 non-null float64\n",
      "MCV   (femtoliters/cell)                                                   941 non-null float64\n",
      "MCH  (picograms/cell)                                                      292 non-null float64\n",
      "MCHC  (grams/deciliter)                                                    278 non-null float64\n",
      "Total Count                                                                940 non-null float64\n",
      "Polymorphs  (%)                                                            950 non-null float64\n",
      "Lymphocytes  (%)                                                           950 non-null float64\n",
      "Monocytes   (%)                                                            941 non-null float64\n",
      "Eosinophils   (%)                                                          942 non-null float64\n",
      "Basophils  (%)                                                             901 non-null float64\n",
      "Platelet Count  (lakhs/mm)                                                 950 non-null float64\n",
      "Total Bilirubin    (mg/dl)                                                 950 non-null object\n",
      "Direct    (mg/dl)                                                          950 non-null float64\n",
      "Indirect     (mg/dl)                                                       895 non-null float64\n",
      "Total Protein     (g/dl)                                                   889 non-null float64\n",
      "Albumin   (g/dl)                                                           941 non-null float64\n",
      "Globulin  (g/dl)                                                           921 non-null float64\n",
      "A/G Ratio                                                                  591 non-null object\n",
      "AL.Phosphatase      (U/L)                                                  940 non-null float64\n",
      "SGOT/AST      (U/L)                                                        950 non-null int64\n",
      "SGPT/ALT (U/L)                                                             950 non-null int64\n",
      "USG Abdomen (diffuse liver or  not)                                        950 non-null object\n",
      "Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)    896 non-null object\n",
      "dtypes: float64(21), int64(5), object(15)\n",
      "memory usage: 311.7+ KB\n"
     ]
    }
   ],
   "source": [
    "test_data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<hr>\n",
    "\n",
    "### Identify the tests that patiants optionally do\n",
    "* Find columns which have null values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "columns = test_data.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "134"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(test_data['Place(location where the patient lives)'].isna())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Place(location where the patient lives) 134\n",
      "TCH 359\n",
      "TG 359\n",
      "LDL 359\n",
      "HDL 368\n",
      "PCV  (%) 30\n",
      "RBC  (million cells/microliter) 552\n",
      "MCV   (femtoliters/cell) 9\n",
      "MCH  (picograms/cell) 658\n",
      "MCHC  (grams/deciliter) 672\n",
      "Total Count 10\n",
      "Monocytes   (%) 9\n",
      "Eosinophils   (%) 8\n",
      "Basophils  (%) 49\n",
      "Indirect     (mg/dl) 55\n",
      "Total Protein     (g/dl) 61\n",
      "Albumin   (g/dl) 9\n",
      "Globulin  (g/dl) 29\n",
      "A/G Ratio 359\n",
      "AL.Phosphatase      (U/L) 10\n",
      "Predicted Value(Out Come-Patient suffering from liver  cirrosis or not) 54\n"
     ]
    }
   ],
   "source": [
    "target_cols = []\n",
    "for col in columns:\n",
    "    if sum(test_data[col].isna()) > 0:\n",
    "        print (col,sum(test_data[col].isna()))\n",
    "        target_cols.append(col)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Place(location where the patient lives)</th>\n",
       "      <th>TCH</th>\n",
       "      <th>TG</th>\n",
       "      <th>LDL</th>\n",
       "      <th>HDL</th>\n",
       "      <th>PCV  (%)</th>\n",
       "      <th>RBC  (million cells/microliter)</th>\n",
       "      <th>MCV   (femtoliters/cell)</th>\n",
       "      <th>MCH  (picograms/cell)</th>\n",
       "      <th>MCHC  (grams/deciliter)</th>\n",
       "      <th>...</th>\n",
       "      <th>Monocytes   (%)</th>\n",
       "      <th>Eosinophils   (%)</th>\n",
       "      <th>Basophils  (%)</th>\n",
       "      <th>Indirect     (mg/dl)</th>\n",
       "      <th>Total Protein     (g/dl)</th>\n",
       "      <th>Albumin   (g/dl)</th>\n",
       "      <th>Globulin  (g/dl)</th>\n",
       "      <th>A/G Ratio</th>\n",
       "      <th>AL.Phosphatase      (U/L)</th>\n",
       "      <th>Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Serial No</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>urban</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>32.0</td>\n",
       "      <td>3.4</td>\n",
       "      <td>90</td>\n",
       "      <td>30</td>\n",
       "      <td>33.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>urban</td>\n",
       "      <td>256.0</td>\n",
       "      <td>156.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>90</td>\n",
       "      <td>30</td>\n",
       "      <td>33.0</td>\n",
       "      <td>...</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>urban</td>\n",
       "      <td>198.0</td>\n",
       "      <td>166.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>94</td>\n",
       "      <td>30</td>\n",
       "      <td>33.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>urban</td>\n",
       "      <td>100.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>82</td>\n",
       "      <td>30</td>\n",
       "      <td>33.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>112.0</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>urban</td>\n",
       "      <td>186.0</td>\n",
       "      <td>174.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>92</td>\n",
       "      <td>30</td>\n",
       "      <td>33.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Place(location where the patient lives)    TCH     TG    LDL   HDL  \\\n",
       "Serial No                                                                      \n",
       "1                                           urban    NaN    NaN    NaN   NaN   \n",
       "2                                           urban  256.0  156.0  105.0  25.0   \n",
       "3                                           urban  198.0  166.0   79.0  36.0   \n",
       "4                                           urban  100.0  160.0  110.0  30.0   \n",
       "5                                           urban  186.0  174.0  104.0  37.0   \n",
       "\n",
       "           PCV  (%)  RBC  (million cells/microliter)  \\\n",
       "Serial No                                              \n",
       "1              32.0                              3.4   \n",
       "2              30.0                              2.2   \n",
       "3              32.0                              4.0   \n",
       "4              20.0                              3.0   \n",
       "5              30.0                              3.0   \n",
       "\n",
       "           MCV   (femtoliters/cell)  MCH  (picograms/cell)  \\\n",
       "Serial No                                                    \n",
       "1                                90                     30   \n",
       "2                                90                     30   \n",
       "3                                94                     30   \n",
       "4                                82                     30   \n",
       "5                                92                     30   \n",
       "\n",
       "           MCHC  (grams/deciliter)  ...  Monocytes   (%)  Eosinophils   (%)  \\\n",
       "Serial No                           ...                                       \n",
       "1                             33.0  ...              3.0                1.0   \n",
       "2                             33.0  ...              6.0                0.2   \n",
       "3                             33.0  ...              1.0                1.0   \n",
       "4                             33.0  ...              5.0                3.0   \n",
       "5                             33.0  ...              3.0                2.0   \n",
       "\n",
       "           Basophils  (%)  Indirect     (mg/dl)  Total Protein     (g/dl)  \\\n",
       "Serial No                                                                   \n",
       "1                     1.0                   0.6                       4.0   \n",
       "2                     1.0                   0.4                       4.0   \n",
       "3                     1.0                   3.0                       4.0   \n",
       "4                     2.0                   4.0                       3.0   \n",
       "5                     1.0                   1.2                       4.0   \n",
       "\n",
       "           Albumin   (g/dl)  Globulin  (g/dl)  A/G Ratio  \\\n",
       "Serial No                                                  \n",
       "1                       2.0               2.0        1.0   \n",
       "2                       2.0               2.0        1.0   \n",
       "3                       3.0               1.0        3.0   \n",
       "4                       1.0               2.0        0.5   \n",
       "5                       3.0               1.0        3.0   \n",
       "\n",
       "           AL.Phosphatase      (U/L)  \\\n",
       "Serial No                              \n",
       "1                              112.0   \n",
       "2                              100.0   \n",
       "3                              120.0   \n",
       "4                              112.0   \n",
       "5                              110.0   \n",
       "\n",
       "           Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)  \n",
       "Serial No                                                                           \n",
       "1                                                        YES                        \n",
       "2                                                        YES                        \n",
       "3                                                        YES                        \n",
       "4                                                        YES                        \n",
       "5                                                        YES                        \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data[target_cols].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 288 entries, 1 to 288\n",
      "Data columns (total 21 columns):\n",
      "Place(location where the patient lives)                                    288 non-null object\n",
      "TCH                                                                        287 non-null float64\n",
      "TG                                                                         287 non-null float64\n",
      "LDL                                                                        287 non-null float64\n",
      "HDL                                                                        286 non-null float64\n",
      "PCV  (%)                                                                   288 non-null float64\n",
      "RBC  (million cells/microliter)                                            288 non-null float64\n",
      "MCV   (femtoliters/cell)                                                   288 non-null int64\n",
      "MCH  (picograms/cell)                                                      288 non-null int64\n",
      "MCHC  (grams/deciliter)                                                    284 non-null float64\n",
      "Total Count                                                                288 non-null int64\n",
      "Monocytes   (%)                                                            287 non-null float64\n",
      "Eosinophils   (%)                                                          287 non-null float64\n",
      "Basophils  (%)                                                             288 non-null float64\n",
      "Indirect     (mg/dl)                                                       288 non-null float64\n",
      "Total Protein     (g/dl)                                                   288 non-null float64\n",
      "Albumin   (g/dl)                                                           288 non-null float64\n",
      "Globulin  (g/dl)                                                           288 non-null float64\n",
      "A/G Ratio                                                                  288 non-null float64\n",
      "AL.Phosphatase      (U/L)                                                  287 non-null float64\n",
      "Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)    288 non-null object\n",
      "dtypes: float64(16), int64(3), object(2)\n",
      "memory usage: 49.5+ KB\n"
     ]
    }
   ],
   "source": [
    "train_data[target_cols].info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Gender</th>\n",
       "      <th>Place(location where the patient lives)</th>\n",
       "      <th>Type of alcohol consumed</th>\n",
       "      <th>Hepatitis B infection</th>\n",
       "      <th>Hepatitis C infection</th>\n",
       "      <th>Diabetes(value)</th>\n",
       "      <th>Blood pressure (mmhg)</th>\n",
       "      <th>Obesity</th>\n",
       "      <th>Family history of cirrhosis/ hereditary</th>\n",
       "      <th>USG Abdomen (liver diffused or not)</th>\n",
       "      <th>Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Serial No</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>no</td>\n",
       "      <td>108/72</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>no</td>\n",
       "      <td>120/70</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>no</td>\n",
       "      <td>110/70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>no</td>\n",
       "      <td>110/70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>positive</td>\n",
       "      <td>positive</td>\n",
       "      <td>no</td>\n",
       "      <td>112/70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Gender Place(location where the patient lives)  \\\n",
       "Serial No                                                  \n",
       "1           male                                   urban   \n",
       "2           male                                   urban   \n",
       "3           male                                   urban   \n",
       "4           male                                   urban   \n",
       "5           male                                   urban   \n",
       "\n",
       "          Type of alcohol consumed Hepatitis B infection  \\\n",
       "Serial No                                                  \n",
       "1                   branded liquor              negative   \n",
       "2                   branded liquor              negative   \n",
       "3                             both              negative   \n",
       "4                   branded liquor              negative   \n",
       "5                   branded liquor              positive   \n",
       "\n",
       "          Hepatitis C infection Diabetes(value)    Blood pressure (mmhg)  \\\n",
       "Serial No                                                                  \n",
       "1                      negative                 no                108/72   \n",
       "2                      negative                 no                120/70   \n",
       "3                      negative                 no                110/70   \n",
       "4                      negative                 no                110/70   \n",
       "5                      positive                 no                112/70   \n",
       "\n",
       "          Obesity Family history of cirrhosis/ hereditary  \\\n",
       "Serial No                                                   \n",
       "1              no                                      no   \n",
       "2              no                                     yes   \n",
       "3              no                                      no   \n",
       "4              no                                      no   \n",
       "5              no                                      no   \n",
       "\n",
       "          USG Abdomen (liver diffused or not)  \\\n",
       "Serial No                                       \n",
       "1                                         YES   \n",
       "2                                         YES   \n",
       "3                                         YES   \n",
       "4                                         YES   \n",
       "5                                         YES   \n",
       "\n",
       "          Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)  \n",
       "Serial No                                                                          \n",
       "1                                                        YES                       \n",
       "2                                                        YES                       \n",
       "3                                                        YES                       \n",
       "4                                                        YES                       \n",
       "5                                                        YES                       "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.select_dtypes(include='object').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data['sbp'] = train_data['Blood pressure (mmhg)'].str.split('/').map(lambda x:int(x[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data['dbp'] = train_data['Blood pressure (mmhg)'].str.split('/').map(lambda x:int(x[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data.drop(columns=['Blood pressure (mmhg)'], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat_col_names = train_data.select_dtypes(include='object').columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "male           234\n",
      "female          51\n",
      "transgender      3\n",
      "Name: Gender, dtype: int64\n",
      "---------\n",
      "urban    147\n",
      "rural    141\n",
      "Name: Place(location where the patient lives), dtype: int64\n",
      "---------\n",
      "country liquor    147\n",
      "both               87\n",
      "branded liquor     54\n",
      "Name: Type of alcohol consumed, dtype: int64\n",
      "---------\n",
      "negative    261\n",
      "positive     27\n",
      "Name: Hepatitis B infection, dtype: int64\n",
      "---------\n",
      "negative    267\n",
      "positive     21\n",
      "Name: Hepatitis C infection, dtype: int64\n",
      "---------\n",
      "Yes    210\n",
      "no      78\n",
      "Name: Diabetes(value)   , dtype: int64\n",
      "---------\n",
      "yes    195\n",
      "no      93\n",
      "Name: Obesity, dtype: int64\n",
      "---------\n",
      "no     273\n",
      "yes     15\n",
      "Name: Family history of cirrhosis/ hereditary, dtype: int64\n",
      "---------\n",
      "YES    288\n",
      "Name: USG Abdomen (liver diffused or not), dtype: int64\n",
      "---------\n",
      "YES    288\n",
      "Name: Predicted Value(Out Come-Patient suffering from liver  cirrosis or not), dtype: int64\n",
      "---------\n"
     ]
    }
   ],
   "source": [
    "for cat_col in cat_col_names:\n",
    "    print(train_data[cat_col].value_counts())\n",
    "    print ('---------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat_col_names.remove('USG Abdomen (liver diffused or not)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)'"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cat_col_names.pop(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Gender',\n",
       " 'Place(location where the patient lives)',\n",
       " 'Type of alcohol consumed',\n",
       " 'Hepatitis B infection',\n",
       " 'Hepatitis C infection',\n",
       " 'Diabetes(value)   ',\n",
       " 'Obesity',\n",
       " 'Family history of cirrhosis/ hereditary']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cat_col_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 288 entries, 1 to 288\n",
      "Data columns (total 32 columns):\n",
      "Age                                               288 non-null int64\n",
      "Duration of alcohol consumption(years)            288 non-null int64\n",
      "Quantity of alcohol consumption (quarters/day)    288 non-null int64\n",
      "TCH                                               287 non-null float64\n",
      "TG                                                287 non-null float64\n",
      "LDL                                               287 non-null float64\n",
      "HDL                                               286 non-null float64\n",
      "Hemoglobin  (g/dl)                                288 non-null float64\n",
      "PCV  (%)                                          288 non-null float64\n",
      "RBC  (million cells/microliter)                   288 non-null float64\n",
      "MCV   (femtoliters/cell)                          288 non-null int64\n",
      "MCH  (picograms/cell)                             288 non-null int64\n",
      "MCHC  (grams/deciliter)                           284 non-null float64\n",
      "Total Count                                       288 non-null int64\n",
      "Polymorphs  (%)                                   288 non-null float64\n",
      "Lymphocytes  (%)                                  288 non-null float64\n",
      "Monocytes   (%)                                   287 non-null float64\n",
      "Eosinophils   (%)                                 287 non-null float64\n",
      "Basophils  (%)                                    288 non-null float64\n",
      "Platelet Count  (lakhs/mm)                        288 non-null float64\n",
      "Total Bilirubin    (mg/dl)                        288 non-null float64\n",
      "Direct    (mg/dl)                                 288 non-null float64\n",
      "Indirect     (mg/dl)                              288 non-null float64\n",
      "Total Protein     (g/dl)                          288 non-null float64\n",
      "Albumin   (g/dl)                                  288 non-null float64\n",
      "Globulin  (g/dl)                                  288 non-null float64\n",
      "A/G Ratio                                         288 non-null float64\n",
      "AL.Phosphatase      (U/L)                         287 non-null float64\n",
      "SGOT/AST      (U/L)                               288 non-null int64\n",
      "SGPT/ALT (U/L)                                    288 non-null int64\n",
      "sbp                                               288 non-null int64\n",
      "dbp                                               288 non-null int64\n",
      "dtypes: float64(22), int64(10)\n",
      "memory usage: 74.2 KB\n"
     ]
    }
   ],
   "source": [
    "train_data.select_dtypes(exclude='object').info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "num_col_names = train_data.select_dtypes(exclude='object').columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "num_col_names.remove('A/G Ratio')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "feature_col_names = cat_col_names + num_col_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_col_name = 'A/G Ratio'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "trainX,testX, trainY, testY = train_test_split(train_data[feature_col_names], train_data[target_col_name])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 302,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.compose import ColumnTransformer, make_column_transformer\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.impute import SimpleImputer\n",
    "from sklearn.preprocessing import StandardScaler, OneHotEncoder, MinMaxScaler, OrdinalEncoder\n",
    "from sklearn.linear_model import LogisticRegression, LinearRegression\n",
    "from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.ensemble import RandomForestRegressor, AdaBoostRegressor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_num = Pipeline(steps=[\n",
    "    ('imputer', SimpleImputer(strategy='median')),\n",
    "    ('scaling',MinMaxScaler())\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* We wanted to try tree based models & ensemble methods\n",
    "* No need to do onehotencoding for them"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_cat = Pipeline(steps=[\n",
    "    ('imputer', SimpleImputer(strategy='constant', fill_value='missing')),\n",
    "    ('encoder',OrdinalEncoder())\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "preprocessor = ColumnTransformer(\n",
    "    transformers=[\n",
    "        ('num', pipeline_num, num_col_names),\n",
    "        ('cat', pipeline_cat, cat_col_names)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_rf = Pipeline(steps=[('preprocessor',preprocessor),('regressor', RandomForestRegressor())])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/awantik/anaconda3/lib/python3.7/site-packages/sklearn/ensemble/forest.py:245: FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22.\n",
      "  \"10 in version 0.20 to 100 in 0.22.\", FutureWarning)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Pipeline(memory=None,\n",
       "         steps=[('preprocessor',\n",
       "                 ColumnTransformer(n_jobs=None, remainder='drop',\n",
       "                                   sparse_threshold=0.3,\n",
       "                                   transformer_weights=None,\n",
       "                                   transformers=[('num',\n",
       "                                                  Pipeline(memory=None,\n",
       "                                                           steps=[('imputer',\n",
       "                                                                   SimpleImputer(add_indicator=False,\n",
       "                                                                                 copy=True,\n",
       "                                                                                 fill_value=None,\n",
       "                                                                                 missing_values=nan,\n",
       "                                                                                 strategy='median',\n",
       "                                                                                 verbose=0)),\n",
       "                                                                  ('scaling',\n",
       "                                                                   MinMaxScaler(copy=True,\n",
       "                                                                                feature_ra...\n",
       "                                   verbose=False)),\n",
       "                ('regressor',\n",
       "                 RandomForestRegressor(bootstrap=True, criterion='mse',\n",
       "                                       max_depth=None, max_features='auto',\n",
       "                                       max_leaf_nodes=None,\n",
       "                                       min_impurity_decrease=0.0,\n",
       "                                       min_impurity_split=None,\n",
       "                                       min_samples_leaf=1, min_samples_split=2,\n",
       "                                       min_weight_fraction_leaf=0.0,\n",
       "                                       n_estimators=10, n_jobs=None,\n",
       "                                       oob_score=False, random_state=None,\n",
       "                                       verbose=0, warm_start=False))],\n",
       "         verbose=False)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_rf.fit(trainX, trainY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9646144370969587"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_rf.score(testX,testY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_lr = Pipeline(steps=[('preprocessor',preprocessor),('regressor', LinearRegression())])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pipeline(memory=None,\n",
       "         steps=[('preprocessor',\n",
       "                 ColumnTransformer(n_jobs=None, remainder='drop',\n",
       "                                   sparse_threshold=0.3,\n",
       "                                   transformer_weights=None,\n",
       "                                   transformers=[('num',\n",
       "                                                  Pipeline(memory=None,\n",
       "                                                           steps=[('imputer',\n",
       "                                                                   SimpleImputer(add_indicator=False,\n",
       "                                                                                 copy=True,\n",
       "                                                                                 fill_value=None,\n",
       "                                                                                 missing_values=nan,\n",
       "                                                                                 strategy='median',\n",
       "                                                                                 verbose=0)),\n",
       "                                                                  ('scaling',\n",
       "                                                                   MinMaxScaler(copy=True,\n",
       "                                                                                feature_ra...\n",
       "                                                                                  dtype=<class 'numpy.float64'>))],\n",
       "                                                           verbose=False),\n",
       "                                                  ['Gender',\n",
       "                                                   'Place(location where the '\n",
       "                                                   'patient lives)',\n",
       "                                                   'Type of alcohol consumed',\n",
       "                                                   'Hepatitis B infection',\n",
       "                                                   'Hepatitis C infection',\n",
       "                                                   'Diabetes(value)   ',\n",
       "                                                   'Obesity',\n",
       "                                                   'Family history of '\n",
       "                                                   'cirrhosis/ hereditary'])],\n",
       "                                   verbose=False)),\n",
       "                ('regressor',\n",
       "                 LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,\n",
       "                                  normalize=False))],\n",
       "         verbose=False)"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_lr.fit(trainX, trainY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7216793255524254"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_lr.score(testX,testY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import GridSearchCV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pipeline(memory=None,\n",
       "         steps=[('preprocessor',\n",
       "                 ColumnTransformer(n_jobs=None, remainder='drop',\n",
       "                                   sparse_threshold=0.3,\n",
       "                                   transformer_weights=None,\n",
       "                                   transformers=[('num',\n",
       "                                                  Pipeline(memory=None,\n",
       "                                                           steps=[('imputer',\n",
       "                                                                   SimpleImputer(add_indicator=False,\n",
       "                                                                                 copy=True,\n",
       "                                                                                 fill_value=None,\n",
       "                                                                                 missing_values=nan,\n",
       "                                                                                 strategy='median',\n",
       "                                                                                 verbose=0)),\n",
       "                                                                  ('scaling',\n",
       "                                                                   MinMaxScaler(copy=True,\n",
       "                                                                                feature_ra...\n",
       "                                   verbose=False)),\n",
       "                ('regressor',\n",
       "                 RandomForestRegressor(bootstrap=True, criterion='mse',\n",
       "                                       max_depth=None, max_features='auto',\n",
       "                                       max_leaf_nodes=None,\n",
       "                                       min_impurity_decrease=0.0,\n",
       "                                       min_impurity_split=None,\n",
       "                                       min_samples_leaf=1, min_samples_split=2,\n",
       "                                       min_weight_fraction_leaf=0.0,\n",
       "                                       n_estimators=10, n_jobs=None,\n",
       "                                       oob_score=False, random_state=None,\n",
       "                                       verbose=0, warm_start=False))],\n",
       "         verbose=False)"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_rf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "rf_para_grid = {\n",
    "    'preprocessor__num__imputer__strategy':['mean'],\n",
    "    'regressor__n_estimators':[1000,1500],\n",
    "    'regressor__n_jobs': [-1]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pipeline(memory=None,\n",
       "         steps=[('preprocessor',\n",
       "                 ColumnTransformer(n_jobs=None, remainder='drop',\n",
       "                                   sparse_threshold=0.3,\n",
       "                                   transformer_weights=None,\n",
       "                                   transformers=[('num',\n",
       "                                                  Pipeline(memory=None,\n",
       "                                                           steps=[('imputer',\n",
       "                                                                   SimpleImputer(add_indicator=False,\n",
       "                                                                                 copy=True,\n",
       "                                                                                 fill_value=None,\n",
       "                                                                                 missing_values=nan,\n",
       "                                                                                 strategy='median',\n",
       "                                                                                 verbose=0)),\n",
       "                                                                  ('scaling',\n",
       "                                                                   MinMaxScaler(copy=True,\n",
       "                                                                                feature_ra...\n",
       "                                                                                  dtype=<class 'numpy.float64'>))],\n",
       "                                                           verbose=False),\n",
       "                                                  ['Gender',\n",
       "                                                   'Place(location where the '\n",
       "                                                   'patient lives)',\n",
       "                                                   'Type of alcohol consumed',\n",
       "                                                   'Hepatitis B infection',\n",
       "                                                   'Hepatitis C infection',\n",
       "                                                   'Diabetes(value)   ',\n",
       "                                                   'Obesity',\n",
       "                                                   'Family history of '\n",
       "                                                   'cirrhosis/ hereditary'])],\n",
       "                                   verbose=False)),\n",
       "                ('regressor',\n",
       "                 LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,\n",
       "                                  normalize=False))],\n",
       "         verbose=False)"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_lr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "lr_para_grid = {\n",
    "    'preprocessor__num__imputer__strategy':['median','mean'],\n",
    "    'regressor__normalize':[True,False]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 342,
   "metadata": {},
   "outputs": [],
   "source": [
    "gs = GridSearchCV(pipeline_rf, param_grid={}, cv=5, n_jobs=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 343,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=5, error_score='raise-deprecating',\n",
       "             estimator=Pipeline(memory=None,\n",
       "                                steps=[('preprocessor',\n",
       "                                        ColumnTransformer(n_jobs=None,\n",
       "                                                          remainder='drop',\n",
       "                                                          sparse_threshold=0.3,\n",
       "                                                          transformer_weights=None,\n",
       "                                                          transformers=[('num',\n",
       "                                                                         Pipeline(memory=None,\n",
       "                                                                                  steps=[('imputer',\n",
       "                                                                                          SimpleImputer(add_indicator=False,\n",
       "                                                                                                        copy=True,\n",
       "                                                                                                        fill_value=None,\n",
       "                                                                                                        missing_values=nan,\n",
       "                                                                                                        strategy='medi...\n",
       "                                                              max_leaf_nodes=None,\n",
       "                                                              min_impurity_decrease=0.0,\n",
       "                                                              min_impurity_split=None,\n",
       "                                                              min_samples_leaf=1,\n",
       "                                                              min_samples_split=2,\n",
       "                                                              min_weight_fraction_leaf=0.0,\n",
       "                                                              n_estimators=10,\n",
       "                                                              n_jobs=None,\n",
       "                                                              oob_score=False,\n",
       "                                                              random_state=None,\n",
       "                                                              verbose=0,\n",
       "                                                              warm_start=False))],\n",
       "                                verbose=False),\n",
       "             iid='warn', n_jobs=-1, param_grid={}, pre_dispatch='2*n_jobs',\n",
       "             refit=True, return_train_score=False, scoring=None, verbose=0)"
      ]
     },
     "execution_count": 343,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gs.fit(trainX, trainY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 344,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 344,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gs.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 345,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8036463593901423"
      ]
     },
     "execution_count": 345,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gs.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LR 0.7216793255524254\n",
      "{'preprocessor__num__imputer__strategy': 'median', 'regressor__normalize': False}\n",
      "RF 0.9774091863412377\n",
      "{'preprocessor__num__imputer__strategy': 'mean', 'regressor__n_estimators': 1500, 'regressor__n_jobs': -1}\n"
     ]
    }
   ],
   "source": [
    "for name,params, pipeline in zip(['LR','RF'],[lr_para_grid, rf_para_grid],[pipeline_lr, pipeline_rf]):\n",
    "    gs = GridSearchCV(pipeline, param_grid=params, cv=5, n_jobs=-1)\n",
    "    gs.fit(trainX, trainY)\n",
    "    print (name, gs.score(testX, testY))\n",
    "    print (gs.best_params_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('preprocessor',\n",
       "  ColumnTransformer(n_jobs=None, remainder='drop', sparse_threshold=0.3,\n",
       "                    transformer_weights=None,\n",
       "                    transformers=[('num',\n",
       "                                   Pipeline(memory=None,\n",
       "                                            steps=[('imputer',\n",
       "                                                    SimpleImputer(add_indicator=False,\n",
       "                                                                  copy=True,\n",
       "                                                                  fill_value=None,\n",
       "                                                                  missing_values=nan,\n",
       "                                                                  strategy='median',\n",
       "                                                                  verbose=0)),\n",
       "                                                   ('scaling',\n",
       "                                                    MinMaxScaler(copy=True,\n",
       "                                                                 feature_range=(0,\n",
       "                                                                                1)))],\n",
       "                                            verbose=False),\n",
       "                                   ['Age',\n",
       "                                    'Duration...\n",
       "                                                                  fill_value='missing',\n",
       "                                                                  missing_values=nan,\n",
       "                                                                  strategy='constant',\n",
       "                                                                  verbose=0)),\n",
       "                                                   ('encoder',\n",
       "                                                    OrdinalEncoder(categories='auto',\n",
       "                                                                   dtype=<class 'numpy.float64'>))],\n",
       "                                            verbose=False),\n",
       "                                   ['Gender',\n",
       "                                    'Place(location where the patient lives)',\n",
       "                                    'Type of alcohol consumed',\n",
       "                                    'Hepatitis B infection',\n",
       "                                    'Hepatitis C infection', 'Diabetes(value)   ',\n",
       "                                    'Obesity',\n",
       "                                    'Family history of cirrhosis/ hereditary'])],\n",
       "                    verbose=False)),\n",
       " ('regressor',\n",
       "  RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=None,\n",
       "                        max_features='auto', max_leaf_nodes=None,\n",
       "                        min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "                        min_samples_leaf=1, min_samples_split=2,\n",
       "                        min_weight_fraction_leaf=0.0, n_estimators=10,\n",
       "                        n_jobs=None, oob_score=False, random_state=None,\n",
       "                        verbose=0, warm_start=False))]"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipeline_rf.steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 354,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.pipeline import make_pipeline\n",
    "from sklearn.compose import make_column_transformer\n",
    "from joblib import dump, load\n",
    "\n",
    "class BuildMlPipeline:\n",
    "    \n",
    "    def __init__(self):\n",
    "        pass\n",
    "        \n",
    "    def set_estimators(self, *args):\n",
    "        estimator_db = {\n",
    "            'randomForestRegressor': RandomForestRegressor(),\n",
    "            'linearRegressor': LinearRegression(),\n",
    "        }\n",
    "        self.estimators = list(map( lambda algo: estimator_db[algo],args))\n",
    "        \n",
    "    def set_scalers(self, *args):\n",
    "        scaler_db = {\n",
    "            'standardscaler':StandardScaler(),\n",
    "            'minmaxscaler':MinMaxScaler(),\n",
    "        }\n",
    "        self.scalers = list(map( lambda scaler: scaler_db[scaler],args))\n",
    "        \n",
    "    def set_samplers(self, *args):\n",
    "        sampler_db = {\n",
    "            'smote':SMOTE(),\n",
    "            'smoteenn':SMOTEENN(),\n",
    "        }\n",
    "        self.samplers = list(map( lambda sampler: sampler_db[sampler],args))\n",
    "        \n",
    "    def set_encoders(self, *args):\n",
    "        encoders_db = {\n",
    "            'ohe':OneHotEncoder(handle_unknown='ignore'),\n",
    "            'oe':OrdinalEncoder(),\n",
    "        }\n",
    "        self.encoders = list(map( lambda encoder: encoders_db[encoder],args))\n",
    "        \n",
    "    def set_hyperparameters(self, params):\n",
    "        self.hyperparameters = params\n",
    "\n",
    "    \n",
    "    def create_pipelines(self):\n",
    "        self.model_pipelines = []\n",
    "        for scaler in self.scalers:\n",
    "            pipeline_num = Pipeline(steps=[('imputer', SimpleImputer(strategy='median')),\n",
    "                                           ('scaling',scaler)])\n",
    "            for encoder in self.encoders:\n",
    "                pipeline_cat = Pipeline(steps=[('imputer', SimpleImputer(strategy='constant', fill_value='missing')),\n",
    "                                               ('encoder',encoder)])\n",
    "                preprocessor = make_column_transformer((pipeline_num, num_col_names),(pipeline_cat, cat_col_names))\n",
    "                \n",
    "                for estimator in self.estimators:\n",
    "                    pipeline  = make_pipeline(preprocessor, estimator)\n",
    "                    self.model_pipelines.append(pipeline)\n",
    "        \n",
    "    \n",
    "    def fit(self, trainX, trainY):\n",
    "        self.gs_pipelines = []\n",
    "        for idx,pipeline in enumerate(self.model_pipelines):\n",
    "            elems = list(map(lambda x:x[0] ,pipeline.steps))\n",
    "            param_grid = {}\n",
    "\n",
    "            for elem in elems:\n",
    "                if elem.lower() in self.hyperparameters:\n",
    "                    param_grid.update(self.hyperparameters[elem])\n",
    "            \n",
    "            gs = GridSearchCV(pipeline, param_grid= param_grid, n_jobs=-1, cv=5)\n",
    "            gs.fit(trainX, trainY)\n",
    "            print (gs.score(testX,testY),  list(map(lambda x:x[0] , gs.best_estimator_.steps)), gs.best_params_)\n",
    "            \n",
    "            dump(gs, 'model'+str(idx)+'.pipeline') \n",
    "            self.gs_pipelines.append(gs)\n",
    "      \n",
    "        \n",
    "    def score(self, testX, testY):\n",
    "        for idx,model in enumerate(self.gs_pipelines):\n",
    "            y_pred = model.best_estimator_.predict(testX)\n",
    "            print (model.best_estimator_)\n",
    "            print (idx,confusion_matrix(y_true=testY,y_pred=y_pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 355,
   "metadata": {},
   "outputs": [],
   "source": [
    "ml_pipeline = BuildMlPipeline()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 356,
   "metadata": {},
   "outputs": [],
   "source": [
    "ml_pipeline.set_estimators('randomForestRegressor', 'linearRegressor')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 357,
   "metadata": {},
   "outputs": [],
   "source": [
    "ml_pipeline.set_encoders('ohe','oe')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 358,
   "metadata": {},
   "outputs": [],
   "source": [
    "ml_pipeline.set_scalers('standardscaler','minmaxscaler')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 359,
   "metadata": {},
   "outputs": [],
   "source": [
    "params_dict = {}\n",
    "params_dict['randomforestregressor'] = {'randomforestregressor__n_estimators':[1000,1500]}\n",
    "params_dict['linearregression'] = {'linearregression__normalize':[True,False]}\n",
    "ml_pipeline.set_hyperparameters(params_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 360,
   "metadata": {},
   "outputs": [],
   "source": [
    "ml_pipeline.create_pipelines()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 361,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9778200038638337 ['columntransformer', 'randomforestregressor'] {'randomforestregressor__n_estimators': 1500}\n",
      "0.717716737009438 ['columntransformer', 'linearregression'] {'linearregression__normalize': True}\n",
      "0.9762025239904748 ['columntransformer', 'randomforestregressor'] {'randomforestregressor__n_estimators': 1000}\n",
      "0.7216793255524249 ['columntransformer', 'linearregression'] {'linearregression__normalize': False}\n",
      "0.977065229915185 ['columntransformer', 'randomforestregressor'] {'randomforestregressor__n_estimators': 1000}\n",
      "0.7174426389536335 ['columntransformer', 'linearregression'] {'linearregression__normalize': True}\n",
      "0.9758530159619229 ['columntransformer', 'randomforestregressor'] {'randomforestregressor__n_estimators': 1000}\n",
      "0.7216793255524254 ['columntransformer', 'linearregression'] {'linearregression__normalize': False}\n"
     ]
    }
   ],
   "source": [
    "ml_pipeline.fit(trainX,trainY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 341,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7174886413205228"
      ]
     },
     "execution_count": 341,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ml_pipeline.__dict__['model_pipelines'][5].score(testX,testY)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Finding out missing A/G ratio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 365,
   "metadata": {},
   "outputs": [],
   "source": [
    "p_data = test_data[test_data['A/G Ratio'].isna()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 366,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 359 entries, 82 to 947\n",
      "Data columns (total 41 columns):\n",
      "Age                                                                        359 non-null int64\n",
      "Gender                                                                     359 non-null object\n",
      "Place(location where the patient lives)                                    324 non-null object\n",
      "Duration of alcohol consumption(years)                                     359 non-null int64\n",
      "Quantity of alcohol consumption (quarters/day)                             359 non-null int64\n",
      "Type of alcohol consumed                                                   359 non-null object\n",
      "Hepatitis B infection                                                      359 non-null object\n",
      "Hepatitis C infection                                                      359 non-null object\n",
      "Diabetes Result                                                            359 non-null object\n",
      "Blood pressure (mmhg)                                                      359 non-null object\n",
      "Obesity                                                                    359 non-null object\n",
      "Family history of cirrhosis/ hereditary                                    359 non-null object\n",
      "TCH                                                                        241 non-null float64\n",
      "TG                                                                         241 non-null object\n",
      "LDL                                                                        241 non-null object\n",
      "HDL                                                                        233 non-null float64\n",
      "Hemoglobin  (g/dl)                                                         359 non-null float64\n",
      "PCV  (%)                                                                   339 non-null float64\n",
      "RBC  (million cells/microliter)                                            132 non-null float64\n",
      "MCV   (femtoliters/cell)                                                   357 non-null float64\n",
      "MCH  (picograms/cell)                                                      54 non-null float64\n",
      "MCHC  (grams/deciliter)                                                    54 non-null float64\n",
      "Total Count                                                                359 non-null float64\n",
      "Polymorphs  (%)                                                            359 non-null float64\n",
      "Lymphocytes  (%)                                                           359 non-null float64\n",
      "Monocytes   (%)                                                            359 non-null float64\n",
      "Eosinophils   (%)                                                          359 non-null float64\n",
      "Basophils  (%)                                                             343 non-null float64\n",
      "Platelet Count  (lakhs/mm)                                                 359 non-null float64\n",
      "Total Bilirubin    (mg/dl)                                                 359 non-null object\n",
      "Direct    (mg/dl)                                                          359 non-null float64\n",
      "Indirect     (mg/dl)                                                       349 non-null float64\n",
      "Total Protein     (g/dl)                                                   349 non-null float64\n",
      "Albumin   (g/dl)                                                           350 non-null float64\n",
      "Globulin  (g/dl)                                                           330 non-null float64\n",
      "A/G Ratio                                                                  0 non-null object\n",
      "AL.Phosphatase      (U/L)                                                  349 non-null float64\n",
      "SGOT/AST      (U/L)                                                        359 non-null int64\n",
      "SGPT/ALT (U/L)                                                             359 non-null int64\n",
      "USG Abdomen (diffuse liver or  not)                                        359 non-null object\n",
      "Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)    353 non-null object\n",
      "dtypes: float64(21), int64(5), object(15)\n",
      "memory usage: 117.8+ KB\n"
     ]
    }
   ],
   "source": [
    "p_data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 367,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/awantik/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "p_data['sbp'] = p_data['Blood pressure (mmhg)'].str.split('/').map(lambda x:int(x[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 368,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/awantik/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "p_data['dbp'] = p_data['Blood pressure (mmhg)'].str.split('/').map(lambda x:int(x[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 369,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Place(location where the patient lives)</th>\n",
       "      <th>Duration of alcohol consumption(years)</th>\n",
       "      <th>Quantity of alcohol consumption (quarters/day)</th>\n",
       "      <th>Type of alcohol consumed</th>\n",
       "      <th>Hepatitis B infection</th>\n",
       "      <th>Hepatitis C infection</th>\n",
       "      <th>Diabetes Result</th>\n",
       "      <th>Blood pressure (mmhg)</th>\n",
       "      <th>...</th>\n",
       "      <th>Albumin   (g/dl)</th>\n",
       "      <th>Globulin  (g/dl)</th>\n",
       "      <th>A/G Ratio</th>\n",
       "      <th>AL.Phosphatase      (U/L)</th>\n",
       "      <th>SGOT/AST      (U/L)</th>\n",
       "      <th>SGPT/ALT (U/L)</th>\n",
       "      <th>USG Abdomen (diffuse liver or  not)</th>\n",
       "      <th>Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)</th>\n",
       "      <th>sbp</th>\n",
       "      <th>dbp</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S.NO</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>38</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>1.2</td>\n",
       "      <td>3.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>116.0</td>\n",
       "      <td>77</td>\n",
       "      <td>40</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>40</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>120/78</td>\n",
       "      <td>...</td>\n",
       "      <td>1.2</td>\n",
       "      <td>4.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>108.0</td>\n",
       "      <td>79</td>\n",
       "      <td>56</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>120</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107</th>\n",
       "      <td>54</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>50</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>120/86</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>120.0</td>\n",
       "      <td>79</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>120</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>3</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>52</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/76</td>\n",
       "      <td>...</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>64</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>2.3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>76</td>\n",
       "      <td>54</td>\n",
       "      <td>YES</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>142</th>\n",
       "      <td>40</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>20</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>2.1</td>\n",
       "      <td>4.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>76</td>\n",
       "      <td>49</td>\n",
       "      <td>YES</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>144</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>Positive</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/80</td>\n",
       "      <td>...</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>156.0</td>\n",
       "      <td>47</td>\n",
       "      <td>35</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>37</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>120/80</td>\n",
       "      <td>...</td>\n",
       "      <td>2.7</td>\n",
       "      <td>30.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>136.0</td>\n",
       "      <td>86</td>\n",
       "      <td>45</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>120</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>64</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>2.3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>76</td>\n",
       "      <td>54</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>40</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>20</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>Positive</td>\n",
       "      <td>Positive</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>2.1</td>\n",
       "      <td>4.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>76</td>\n",
       "      <td>49</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>Positive</td>\n",
       "      <td>Positive</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/80</td>\n",
       "      <td>...</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>156.0</td>\n",
       "      <td>47</td>\n",
       "      <td>35</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>819</th>\n",
       "      <td>55</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>142/84</td>\n",
       "      <td>...</td>\n",
       "      <td>1.8</td>\n",
       "      <td>2.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>61</td>\n",
       "      <td>46</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>820</th>\n",
       "      <td>55</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>142/84</td>\n",
       "      <td>...</td>\n",
       "      <td>1.8</td>\n",
       "      <td>2.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>61</td>\n",
       "      <td>46</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>821</th>\n",
       "      <td>55</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>142/84</td>\n",
       "      <td>...</td>\n",
       "      <td>1.8</td>\n",
       "      <td>2.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>61</td>\n",
       "      <td>46</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>822</th>\n",
       "      <td>55</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>142/84</td>\n",
       "      <td>...</td>\n",
       "      <td>1.8</td>\n",
       "      <td>2.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>61</td>\n",
       "      <td>46</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>823</th>\n",
       "      <td>55</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>Positive</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>142/84</td>\n",
       "      <td>...</td>\n",
       "      <td>1.8</td>\n",
       "      <td>2.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>61</td>\n",
       "      <td>46</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>824</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>1.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>825</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>826</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>Positive</td>\n",
       "      <td>Positive</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>827</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>1.2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>828</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>829</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>urban</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>830</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>urban</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>831</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>urban</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>832</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>833</th>\n",
       "      <td>55</td>\n",
       "      <td>female</td>\n",
       "      <td>urban</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>Positive</td>\n",
       "      <td>Positive</td>\n",
       "      <td>YES</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>8.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140.0</td>\n",
       "      <td>66</td>\n",
       "      <td>44</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>913</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>915</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>917</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>919</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>921</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>923</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>925</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>927</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>130/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>929</th>\n",
       "      <td>49</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>both</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>120/90</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>150.0</td>\n",
       "      <td>56</td>\n",
       "      <td>43</td>\n",
       "      <td>no</td>\n",
       "      <td>YES</td>\n",
       "      <td>120</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>933</th>\n",
       "      <td>48</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>NO</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>3.8</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>70.0</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>936</th>\n",
       "      <td>54</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>NO</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>5.2</td>\n",
       "      <td>3.4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>86.0</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>937</th>\n",
       "      <td>72</td>\n",
       "      <td>female</td>\n",
       "      <td>urban</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>NO</td>\n",
       "      <td>120/80</td>\n",
       "      <td>...</td>\n",
       "      <td>4.2</td>\n",
       "      <td>3.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>120</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>943</th>\n",
       "      <td>48</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>NO</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>3.8</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>70.0</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>946</th>\n",
       "      <td>54</td>\n",
       "      <td>female</td>\n",
       "      <td>rural</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>NO</td>\n",
       "      <td>110/70</td>\n",
       "      <td>...</td>\n",
       "      <td>5.2</td>\n",
       "      <td>3.4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>86.0</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>947</th>\n",
       "      <td>72</td>\n",
       "      <td>female</td>\n",
       "      <td>urban</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>branded liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>NO</td>\n",
       "      <td>120/80</td>\n",
       "      <td>...</td>\n",
       "      <td>4.2</td>\n",
       "      <td>3.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>120</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>359 rows × 43 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Age   Gender Place(location where the patient lives)  \\\n",
       "S.NO                                                         \n",
       "82     38     male                                   urban   \n",
       "90     40     male                                   urban   \n",
       "103    52     male                                   rural   \n",
       "104    45     male                                   urban   \n",
       "107    54     male                                   rural   \n",
       "...   ...      ...                                     ...   \n",
       "936    54     male                                   rural   \n",
       "937    72  female                                    urban   \n",
       "943    48     male                                   urban   \n",
       "946    54  female                                    rural   \n",
       "947    72  female                                    urban   \n",
       "\n",
       "      Duration of alcohol consumption(years)  \\\n",
       "S.NO                                           \n",
       "82                                        10   \n",
       "90                                        10   \n",
       "103                                       20   \n",
       "104                                       15   \n",
       "107                                       20   \n",
       "...                                      ...   \n",
       "936                                        5   \n",
       "937                                        4   \n",
       "943                                       10   \n",
       "946                                        5   \n",
       "947                                        4   \n",
       "\n",
       "      Quantity of alcohol consumption (quarters/day) Type of alcohol consumed  \\\n",
       "S.NO                                                                            \n",
       "82                                                 2           country liquor   \n",
       "90                                                 1           country liquor   \n",
       "103                                                2           country liquor   \n",
       "104                                                2           country liquor   \n",
       "107                                                2           country liquor   \n",
       "...                                              ...                      ...   \n",
       "936                                                3           country liquor   \n",
       "937                                                3           branded liquor   \n",
       "943                                                4           branded liquor   \n",
       "946                                                3           country liquor   \n",
       "947                                                3           branded liquor   \n",
       "\n",
       "     Hepatitis B infection Hepatitis C infection Diabetes Result  \\\n",
       "S.NO                                                               \n",
       "82                negative              negative             YES   \n",
       "90                negative              negative             YES   \n",
       "103               negative              negative             YES   \n",
       "104               negative              negative             YES   \n",
       "107               negative              negative             YES   \n",
       "...                    ...                   ...             ...   \n",
       "936               negative              negative              NO   \n",
       "937               negative              negative              NO   \n",
       "943               negative              negative              NO   \n",
       "946               negative              negative              NO   \n",
       "947               negative              negative              NO   \n",
       "\n",
       "     Blood pressure (mmhg)  ... Albumin   (g/dl) Globulin  (g/dl)  A/G Ratio  \\\n",
       "S.NO                        ...                                                \n",
       "82                  110/70  ...              1.2              3.8        NaN   \n",
       "90                  120/78  ...              1.2              4.8        NaN   \n",
       "103                 130/76  ...              2.0              3.0        NaN   \n",
       "104                 110/70  ...              2.5              2.8        NaN   \n",
       "107                 130/76  ...              2.0              3.0        NaN   \n",
       "...                    ...  ...              ...              ...        ...   \n",
       "936                 110/70  ...              5.2              3.4        NaN   \n",
       "937                 120/80  ...              4.2              3.5        NaN   \n",
       "943                 110/70  ...              3.8              3.0        NaN   \n",
       "946                 110/70  ...              5.2              3.4        NaN   \n",
       "947                 120/80  ...              4.2              3.5        NaN   \n",
       "\n",
       "     AL.Phosphatase      (U/L) SGOT/AST      (U/L)  SGPT/ALT (U/L)  \\\n",
       "S.NO                                                                 \n",
       "82                       116.0                  77              40   \n",
       "90                       108.0                  79              56   \n",
       "103                      110.0                  86              79   \n",
       "104                        NaN                  90              84   \n",
       "107                      110.0                  86              79   \n",
       "...                        ...                 ...             ...   \n",
       "936                       86.0                 110              70   \n",
       "937                      110.0                 110              70   \n",
       "943                       70.0                 110              70   \n",
       "946                       86.0                 110              70   \n",
       "947                      110.0                 110              70   \n",
       "\n",
       "      USG Abdomen (diffuse liver or  not)  \\\n",
       "S.NO                                        \n",
       "82                                    YES   \n",
       "90                                    YES   \n",
       "103                                   YES   \n",
       "104                                   YES   \n",
       "107                                   YES   \n",
       "...                                   ...   \n",
       "936                                    no   \n",
       "937                                    no   \n",
       "943                                    no   \n",
       "946                                    no   \n",
       "947                                    no   \n",
       "\n",
       "      Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)  \\\n",
       "S.NO                                                                            \n",
       "82                                                  YES                         \n",
       "90                                                  YES                         \n",
       "103                                                 NaN                         \n",
       "104                                                 NaN                         \n",
       "107                                                 YES                         \n",
       "...                                                 ...                         \n",
       "936                                                  no                         \n",
       "937                                                  no                         \n",
       "943                                                  no                         \n",
       "946                                                  no                         \n",
       "947                                                  no                         \n",
       "\n",
       "      sbp  dbp  \n",
       "S.NO            \n",
       "82    110   70  \n",
       "90    120   78  \n",
       "103   130   76  \n",
       "104   110   70  \n",
       "107   130   76  \n",
       "...   ...  ...  \n",
       "936   110   70  \n",
       "937   120   80  \n",
       "943   110   70  \n",
       "946   110   70  \n",
       "947   120   80  \n",
       "\n",
       "[359 rows x 43 columns]"
      ]
     },
     "execution_count": 369,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 370,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/awantik/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py:4097: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  errors=errors,\n"
     ]
    }
   ],
   "source": [
    "p_data.drop(columns=['Blood pressure (mmhg)'], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 371,
   "metadata": {},
   "outputs": [],
   "source": [
    "loaded_pl = load('model0.pipeline')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 374,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/awantik/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py:1404: FutureWarning: \n",
      "Passing list-likes to .loc or [] with any missing label will raise\n",
      "KeyError in the future, you can use .reindex() as an alternative.\n",
      "\n",
      "See the documentation here:\n",
      "https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike\n",
      "  return self._getitem_tuple(key)\n",
      "/home/awantik/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "p_data['Predicted A/G Ratio'] = loaded_pl.predict(p_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 375,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Place(location where the patient lives)</th>\n",
       "      <th>Duration of alcohol consumption(years)</th>\n",
       "      <th>Quantity of alcohol consumption (quarters/day)</th>\n",
       "      <th>Type of alcohol consumed</th>\n",
       "      <th>Hepatitis B infection</th>\n",
       "      <th>Hepatitis C infection</th>\n",
       "      <th>Diabetes Result</th>\n",
       "      <th>Obesity</th>\n",
       "      <th>...</th>\n",
       "      <th>Globulin  (g/dl)</th>\n",
       "      <th>A/G Ratio</th>\n",
       "      <th>AL.Phosphatase      (U/L)</th>\n",
       "      <th>SGOT/AST      (U/L)</th>\n",
       "      <th>SGPT/ALT (U/L)</th>\n",
       "      <th>USG Abdomen (diffuse liver or  not)</th>\n",
       "      <th>Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)</th>\n",
       "      <th>sbp</th>\n",
       "      <th>dbp</th>\n",
       "      <th>Predicted A/G Ratio</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S.NO</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>38</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>yes</td>\n",
       "      <td>...</td>\n",
       "      <td>3.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>116.0</td>\n",
       "      <td>77</td>\n",
       "      <td>40</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>0.331002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>40</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>yes</td>\n",
       "      <td>...</td>\n",
       "      <td>4.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>108.0</td>\n",
       "      <td>79</td>\n",
       "      <td>56</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>120</td>\n",
       "      <td>78</td>\n",
       "      <td>0.269712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>52</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>yes</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "      <td>0.670960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>45</td>\n",
       "      <td>male</td>\n",
       "      <td>urban</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>yes</td>\n",
       "      <td>...</td>\n",
       "      <td>2.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>90</td>\n",
       "      <td>84</td>\n",
       "      <td>YES</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110</td>\n",
       "      <td>70</td>\n",
       "      <td>0.908337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107</th>\n",
       "      <td>54</td>\n",
       "      <td>male</td>\n",
       "      <td>rural</td>\n",
       "      <td>20</td>\n",
       "      <td>2</td>\n",
       "      <td>country liquor</td>\n",
       "      <td>negative</td>\n",
       "      <td>negative</td>\n",
       "      <td>YES</td>\n",
       "      <td>yes</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>86</td>\n",
       "      <td>79</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>130</td>\n",
       "      <td>76</td>\n",
       "      <td>0.672391</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 43 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Age Gender Place(location where the patient lives)  \\\n",
       "S.NO                                                       \n",
       "82     38   male                                   urban   \n",
       "90     40   male                                   urban   \n",
       "103    52   male                                   rural   \n",
       "104    45   male                                   urban   \n",
       "107    54   male                                   rural   \n",
       "\n",
       "      Duration of alcohol consumption(years)  \\\n",
       "S.NO                                           \n",
       "82                                        10   \n",
       "90                                        10   \n",
       "103                                       20   \n",
       "104                                       15   \n",
       "107                                       20   \n",
       "\n",
       "      Quantity of alcohol consumption (quarters/day) Type of alcohol consumed  \\\n",
       "S.NO                                                                            \n",
       "82                                                 2           country liquor   \n",
       "90                                                 1           country liquor   \n",
       "103                                                2           country liquor   \n",
       "104                                                2           country liquor   \n",
       "107                                                2           country liquor   \n",
       "\n",
       "     Hepatitis B infection Hepatitis C infection Diabetes Result Obesity  ...  \\\n",
       "S.NO                                                                      ...   \n",
       "82                negative              negative             YES     yes  ...   \n",
       "90                negative              negative             YES     yes  ...   \n",
       "103               negative              negative             YES     yes  ...   \n",
       "104               negative              negative             YES     yes  ...   \n",
       "107               negative              negative             YES     yes  ...   \n",
       "\n",
       "     Globulin  (g/dl)  A/G Ratio AL.Phosphatase      (U/L)  \\\n",
       "S.NO                                                         \n",
       "82                3.8        NaN                     116.0   \n",
       "90                4.8        NaN                     108.0   \n",
       "103               3.0        NaN                     110.0   \n",
       "104               2.8        NaN                       NaN   \n",
       "107               3.0        NaN                     110.0   \n",
       "\n",
       "     SGOT/AST      (U/L)  SGPT/ALT (U/L)  USG Abdomen (diffuse liver or  not)  \\\n",
       "S.NO                                                                            \n",
       "82                    77              40                                  YES   \n",
       "90                    79              56                                  YES   \n",
       "103                   86              79                                  YES   \n",
       "104                   90              84                                  YES   \n",
       "107                   86              79                                  YES   \n",
       "\n",
       "      Predicted Value(Out Come-Patient suffering from liver  cirrosis or not)  \\\n",
       "S.NO                                                                            \n",
       "82                                                  YES                         \n",
       "90                                                  YES                         \n",
       "103                                                 NaN                         \n",
       "104                                                 NaN                         \n",
       "107                                                 YES                         \n",
       "\n",
       "      sbp  dbp  Predicted A/G Ratio  \n",
       "S.NO                                 \n",
       "82    110   70             0.331002  \n",
       "90    120   78             0.269712  \n",
       "103   130   76             0.670960  \n",
       "104   110   70             0.908337  \n",
       "107   130   76             0.672391  \n",
       "\n",
       "[5 rows x 43 columns]"
      ]
     },
     "execution_count": 375,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
